package ua.yandex.skipass;

import java.util.Calendar;

public enum WeekdayDayType implements DayType {

    MORNING(0) {
        private static final int VALID_FROM_HOUR = 9;
        private static final int VALID_UNTIL_HOUR = 13;

        @Override
        public DateChecker getDateChecker() {
            DateChecker morningDateChecker = DEFAULT_DATE_CHECKER.makeEqual();
            morningDateChecker.resetHours();
            morningDateChecker.setHoursAsValid(VALID_FROM_HOUR, VALID_UNTIL_HOUR);
            return morningDateChecker;
        }

        @Override
        public int getValidUntilHour() {
            return VALID_UNTIL_HOUR;
        }

    }, EVENING(0) {
        private static final int VALID_FROM_HOUR = 13;
        private static final int VALID_UNTIL_HOUR = 17;

        @Override
        public DateChecker getDateChecker() {
            DateChecker morningDateChecker = DEFAULT_DATE_CHECKER.makeEqual();
            morningDateChecker.resetHours();
            morningDateChecker.setHoursAsValid(VALID_FROM_HOUR, VALID_UNTIL_HOUR);
            return morningDateChecker;
        }

        @Override
        public int getValidUntilHour() {
            return VALID_UNTIL_HOUR;
        }

    }, ONE_DAY(1), TWO_DAYS(2), FIVE_DAYS(5);

    public static final int VALID_FROM_HOUR = 9;
    public static final int VALID_UNTIL_HOUR = 17;
    public static final DateChecker DEFAULT_DATE_CHECKER = new DateChecker();
    static {
        DEFAULT_DATE_CHECKER.setDayAsValid(Calendar.MONDAY);
        DEFAULT_DATE_CHECKER.setDayAsValid(Calendar.TUESDAY);
        DEFAULT_DATE_CHECKER.setDayAsValid(Calendar.WEDNESDAY);
        DEFAULT_DATE_CHECKER.setDayAsValid(Calendar.THURSDAY);
        DEFAULT_DATE_CHECKER.setDayAsValid(Calendar.FRIDAY);
        DEFAULT_DATE_CHECKER.setHoursAsValid(VALID_FROM_HOUR, VALID_UNTIL_HOUR);
    }
    private int duration;

    WeekdayDayType(int duration) {
        this.duration = duration;
    }

    @Override
    public  int getValidUntilHour() {
        return VALID_UNTIL_HOUR;
    }

    @Override
    public int duration() {
        return duration;
    }

    @Override
    public DateChecker getDateChecker() {
        return DEFAULT_DATE_CHECKER;
    }

}
